package com.emmmya.harinCheck.pojo;

import com.emmmya.harinCheck.annotation.EnumGetValue;

import java.util.HashMap;
import java.util.Map;

/**
 * @author laijieguan@sunwodao.com
 * @version 1.0
 * @date 2022-07-04 10:06:00
 */
public enum Status {
    SUCCESS(200,"完成"),
    FAIL(500,"失败");


    private Integer code;
    private String value;

    private static Map<Integer,String> dataMap = null;



    Status(Integer code, String value) {
        this.code = code;
        this.value = value;
    }

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }


    //根据传入的code动态获取value
    @EnumGetValue
    public static String getValueByCode(Integer code) {
        //获取所有枚举集合
        Status [] stauss = values();
        for (Status s : stauss) {
            if (s.getCode().compareTo(code) == 0) {
                return s.getValue();
            }
        }
        return null;
    }

    public static Map<Integer,String> getDataMap(){
        if(dataMap!=null) {
            return dataMap;
        }else{
            dataMap = new HashMap<Integer,String>();
            for (Status value : Status.values()) {
                dataMap.put(value.code,value.value);
            }
            return dataMap;
        }
    }

    @Override
    public String toString() {
        return value;
    }
}
